const router = require('koa-router')();
const sql = require('../database')
const Mock = require('mockjs')
const util = require('../util/util')
const send = require('koa-send'); // "koa-send": "^4.1.0"

// app.use(koaBody({multipart: true}));
//产品数据管理-列表--鲁亮堂
router.post('/crm/product/getProductList', async(ctx, next) => {
  //将json传入 Mock.mock 方法中，生成的数据返回给浏览器
  var json = util.getJsonFile('product.json');
  var data = Mock.mock(json.productList);
  ctx.body =data
})
//产品数据管理-新增和修改初始化--鲁亮堂
router.get('/crm/product/getProductInit', async(ctx, next) => {
  var json = util.getJsonFile('product.json');
  var data = Mock.mock(json.getProductInit);
  ctx.body = data
})
//产品数据管理-下载模板--鲁亮堂
router.get('/crm/product/downloadTemplate',  async (ctx,next) => { 
  let fileName = '123.xlsx'; 
    // Set Content-Disposition to "attachment" to signal the client to prompt for download.
    // Optionally specify the filename of the download.
    // 设置实体头（表示消息体的附加信息的头字段）,提示浏览器以文件下载的方式打开
    // 也可以直接设置 ctx.set("Content-disposition", "attachment; filename=" + fileName);
    ctx.attachment(fileName);
    await send(ctx, fileName, { root: __dirname  });
})
//产品数据删除
router.post('/crm/product/delProduct',  async (ctx,next) => { 
  var json = util.getJsonFile('product.json');
  var data = Mock.mock(json.test);
  ctx.body = data
})
//产品数据导出
router.get('/crm/product/exportProduct',  async (ctx,next) => { 
  var json = util.getJsonFile('product.json');
  var data = Mock.mock(json.test);
  ctx.body = data
})
//导入
router.post('/crm/product/importProduct',  async (ctx,next) => { 
  var json = util.getJsonFile('product.json');
  var data = Mock.mock(json.test);
  ctx.body = data
})
router.post('/crm/product/recheckProduct',  async (ctx,next) => { 
  var json = util.getJsonFile('product.json');
  var data = Mock.mock(json.test);
  ctx.body = data
})
router.post('/crm/product/addProduct',  async (ctx,next) => { 
  var json = util.getJsonFile('product.json');
  var data = Mock.mock(json.test);
  ctx.body = data
})


module.exports = router